<template>
  <div class="brief flex-column justify-between h-100P">
    <div>
      <div class="brief-msg">
        <div class="title box main-title">
          <div class="align-center mg-bottom-10">
            <div class="fw-600">基本信息</div>

          </div>
          <el-form ref="briefForm" :model="formData" :rules="briefMsgRules" label-width="99px" label-suffix="：" inline>
            <el-form-item style="width: 45%;" label="任务名称" prop="name">
              <span v-show="!isBriefEditModel">{{ algTask.name }}</span>
              <el-input v-show="isBriefEditModel" v-model="formData.name" clearable placeholder="请输入任务名称"></el-input>
              <svg-icon
                class="h-8 link-text mg-left-10"
                style="cursor: pointer"
                icon-class="edit"
                @click="isBriefEditModel=true"
                v-show="!isBriefEditModel"
              ></svg-icon>
            </el-form-item>
            <el-form-item style="width: 45%;" label="所属算法">{{ formData.algAbilityName }}</el-form-item>
            <el-form-item style="width: 45%;" label="供应商" prop="algOriginEnum">
              <span>{{ algTask.algOriginName }}</span>
            </el-form-item>
            <el-form-item style="width: 45%;" label="在运行设备">
              {{ formData.deviceVos ? formData.deviceVos.length : 0 }}
            </el-form-item>
            <el-form-item style="width: 45%;" label="创建时间">
              {{ formData.updateTime || formData.createTime|dateTimeFormatter }}
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="remind-type box">
        <div class="title main-title fw-600">告警方式</div>
        <div class="mg-top-20">
          <el-radio-group v-model="formData.remind" @change="handleEdit">
            <el-radio :label="false">无通知</el-radio>
            <el-radio :label="true">有通知</el-radio>
          </el-radio-group>
        </div>
        <div class="remindBox" v-if="formData.remind">
          <el-checkbox-group v-model="formData.remindModeEnumList" @change="handleEdit">
            <div class="flex">
              <el-checkbox class="checkbox" label="WEB_MSG">站内信</el-checkbox>
            </div>
            <!--          <div class="flex">-->
            <!--            <el-checkbox class="checkbox" label="SHORT_MSG">短信</el-checkbox>-->
            <!--            <el-input class="input-box" placeholder="请输入通知的手机号码"></el-input>-->
            <!--            <el-button type="text" class="link-text">添加</el-button>-->
            <!--          </div>-->
            <div class="flex">
              <el-checkbox class="checkbox" label="MODEL_UE4">模型内闪烁</el-checkbox>
            </div>
            <!--          <div class="flex">-->
            <!--            <el-checkbox class="checkbox" label="EMAIL">邮件</el-checkbox>-->
            <!--            <el-input class="input-box" placeholder="请输入通知的手机号码"></el-input>-->
            <!--            <el-button type="text" class="link-text">添加</el-button>-->
            <!--          </div>-->
            <div class="flex">
              <el-checkbox class="checkbox" label="PHONE">电话</el-checkbox>
            </div>
            <div class="flex">
              <el-checkbox class="checkbox" label="WECHAT">微信</el-checkbox>
            </div>
          </el-checkbox-group>
        </div>
      </div>
    </div>
    <div class="justify-center ">
      <el-button type="primary" @click="handleSubmit">提交</el-button>
      <el-button @click="handleReset">取消</el-button>
    </div>
  </div>
</template>

<script>

import { AlgOriginEnum, RemindModeEnum } from '@/views/algorithm/consts'
import { apiUpdateAlgTask } from '@/views/algorithm/alg-task/api'

export default {
  name: 'Brief',
  props: {
    algTask: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      isEditFlag: false,
      formData: {
        remindModeEnumList: []
      },
      isBriefEditModel: false
    }
  },
  watch: {
    algTask(value) {
      this.formData = { ...value }

      if (!this.formData.remindModeEnumList) {
        this.formData.remindModeEnumList = []
      }
    },
    isBriefEditModel() {
      this.handleEdit()
    }
  },
  computed: {
    briefMsgRules() {
      return {
        name: [{ required: this.isBriefEditModel, message: '任务名称不能为空', trigger: ['change', 'blur'] }],
        algOriginEnum: [{ required: this.isBriefEditModel, message: '供应商不能为空', trigger: 'change' }]
      }
    },
    RemindModeEnumList() {
      const toList = []
      for (const [key, value] of RemindModeEnum) {
        toList.push({
          label: value,
          value: key
        })
      }
      return toList
    },
    algOrigin() {
      const toList = []
      for (const [key, value] of AlgOriginEnum) {
        toList.push({
          label: value,
          value: key
        })
      }
      return toList
    }
  },
  methods: {
    handleReset() {
      this.$refs.briefForm.resetFields()
      this.formData = { ...this.algTask, remindModeEnumList: [] }
      this.isBriefEditModel = false
      this.isEditFlag = false
    },
    handleEdit() {
      console.log('handleEdit')
      this.isEditFlag = true
    },
    handleSubmit() {
      this.isEditFlag = false
      apiUpdateAlgTask(this.formData).then(() => {
        this.$message.success('提交成功')
        this.$emit('change')
      })
    }

  }
}
</script>

<style scoped lang="scss">
.brief {
  .box {
    margin-bottom: 10px;
    padding: 20px;
    border: 1px solid #999999;
    border-radius: 4px;
  }

  .remindBox {
    position: relative;
    margin-top: 10px;
    padding: vw(20px);
    box-shadow: 0px 1px 8px 0px rgba(29, 29, 29, 0.10), 0px -1px 8px 0px rgba(29, 29, 29, 0.10);


    &::after {
      position: absolute;
      top: -5px;
      left: 130px;
      content: '';
      width: 10px;
      height: 10px;
      background: white;
      transform: rotate(135deg);
      box-shadow: 0px 1px 8px 0px rgba(29, 29, 29, 0.10), 0 0 0 0;
    }


    .checkbox {
      width: vw(120px);
      line-height: 25px;
    }

    .input-box {
      width: vw(350px);
    }
  }


  ::v-deep {
    .el-form-item__label {
      color: $first-title-color;
    }

    .el-form-item__content {
      color: $second-title-color;
    }

    .el-form-item__error {
      top: 50%;
      left: calc(100% + 10px);
      transform: translateY(-50%);
      font-size: 12px;
      padding-top: 0;
      white-space: nowrap;
    }

    .el-form-item {
      margin-bottom: 0;
    }
  }
}
</style>
